package com.lagou.homework1_4;

import java.io.File;

public class Test02 {

    public static void main(String[] args) {

        String dir = "D:/bbb/";
        File file = new File(dir);
        Test02.delDir(file);
        System.out.println("删除目录成功");
    }

    /**
     * 删除某个目录
     * @param file
     */
    public static void delDir(File file) {

        if (file.isFile()) {
            System.out.println("正在删除文件:" + file.getAbsolutePath());
            file.delete();
        } else {
            File[] listFiles = file.listFiles();
            if (listFiles.length == 0) {
                System.out.println("正在删除文件:" + file.getAbsolutePath());
                file.delete();
            }

            for (File f : listFiles) {
                delDir(f);
            }
        }
        System.out.println("正在删除文件:" + file.getAbsolutePath());
        file.delete();
    }
}
